#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>

int main (void) {
	mouseevent_t mouse;
    int fd;
	fd = open("/dev/mouse", O_RDONLY);
	if ( fd == -1 ) {
		printf("The mouse device could not be opened\n");
		return;
	}
	printf("Press both right and left click to exit...\n");
	while(1) {
		/* Non-blocking mouse....COOL!!!! */
		while ( read(fd, &mouse, sizeof(mouse)) != sizeof(mouse) ) {}
		printf("Mouse[dx=%d, dy=%d, leftClick=%s, rightClick=%s]\n", mouse.dx, mouse.dy, (mouse.leftClick)?"true":"false", (mouse.rightClick)?"true":"false");
		if ( mouse.rightClick && mouse.leftClick ) {
			printf("Bye bye dude...\n");
			close(fd);
			return;
		}
	}
	return 0;
}
